<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%@ taglib uri="/WEB-INF/tld/orderStatus.tld" prefix="os" %>
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt" %>
<style> 
#tuifei_form input { width:15em; padding:4px; border:1px solid #CCC; }
#tuifei_form input:focus { border-color:#426DC9; }
#tuifei_form .form-error { background:#FFFBFC; border-color:#F00 !important; }
</style>
<form id="tuifei_form" action="#" method="post">
 <table border="0" cellpadding="0" cellspacing="0" width="100%" class="mytable">
		<tr>
			<th class="left" width="20%">退废类型</th>
			<td class="border-top">
				<input type="radio" value="B" checked="checked" name="tp.type" id="rd_t" /><label for="rd_t">退票</label>
				<input type="radio" value="A" name="tp.type" id="rd_f" /><label for="rd_f">废票</label>
				<select id="cause">
					<option value="">选择退费原因</option>
					<option value="1">当日作废</option>
					<option value="2">按客规自愿退票</option>
					<option value="3">非自愿及特殊退票</option>
					<option value="4">航班延误申请全退</option>
				</select>
			</td>
		</tr>
		<tr>
			<th class="left">平台取消</th>
			<td>
				<input type="radio" value="否" checked="checked" name="tp.isCancelSeat" id="cd_n" /><label for="cd_n">否</label>
				<input type="radio" value="是" name="tp.isCancelSeat" id="cd_y" /><label for="cd_y">是</label>
				<br/><label>备注说明(<font style="color: red;">*</font>)&nbsp;<input style="width:60%" name="tp.remarks" /></label>
			</td>
		</tr>
		<tr>
			<th class="left">订单金额</th>
			<td>
				<fmt:formatNumber value="${children.fare+children.tax}" pattern="#.##"  />
			</td>
		</tr>
		<tr>
			<th class="left">退款金额</th>
			<td>
				<input value="" name="refund.amount" id="amount" />
			</td>
		</tr>
		<tr>
			<th class="left">退款备注</th>
			<td>
				<textarea rows="5" cols="50%" style="overflow: hidden;" name="refund.remarks" id="remarks"></textarea>
			</td>
		</tr>
	</table>
	<input name="orderid" value="${children.id}" type="text" />
	<input name="tp.orderNo" id="orderNo" value="${children.terraceSn}" type="text" />
	<input name="tp.repeal" id="repeal" value="" type="text" />
	<input name="tp.personName" id="personName" value="" type="text" />
	<input name="tp.cause" id="causedesc" value="" type="text" />
	<input name="tp.ticketNo" id="ticketNo" value="" type="text" />
	<br/>
	<table width="100%" cellpadding="0" cellspacing="0" class="mytable" id="tb_person">
	
		<tr>
			<th class="left" colspan="4">乘客信息</th>
		</tr>
		<s:if test="#request.persones.size()>0">
		<tr>
			<td class="left" width="10px">&nbsp;</td>
			<td style="text-align: center;">乘客姓名</td>
			<td style="text-align: center;">票号信息</td>
			<td style="text-align: center;">状态</td>
		</tr>
		<s:iterator value="#request.persones" var="person">
			<tr>
				<td class="left" width="10px">
					<input type="checkbox" name="ckPerson" value="${passenger }" />
				</td>
				<td>${passenger}</td>
				<s:if test="#request.children.traltype==1">
					<td>${ticketNo!=null?ticketNo:'——'}</td>
					<td><os:personState state="${state}"/></td>	
				</s:if>
				<s:else>
					<td>${secTicketNo!=null?secTicketNo:'——'}</td>
					<td><os:personState state="${secState}"/></td>
				</s:else>
			</tr>
		</s:iterator>
		</s:if>
		<s:else>
		<tr>
			<td class="left" colspan="4">
			没有符合条件的乘客……</td>
		</s:else>
	</table>
	
</form>
<script type="text/dialog">
var api = this,
form = $('#tuifei_form'),
tpCause = document.getElementById('causedesc'),
tpPerson = document.getElementById('personName'),
tpTicketNo = document.getElementById('ticketNo'),
tpRepeal = document.getElementById('repeal'),
remark = document.getElementById('remarks'),
amount = document.getElementById('amount');
api.title('办理退废').button(
{
	name:'确定',
	focus:true,
	callback:function(){

		if($.trim(tpCause.value)==''){art.dialog.tips('请选择退费原因！',2);$('#cause').focus();return false;}
		if($.trim(remark.value)==''){art.dialog.tips('请填写备注信息',2);remark.focus();return false;}
		if($.trim(amount.value)==''){art.dialog.tips('请填写需退款的金额！',2);amount.focus();return false;}
		else{
			if(/^[0-9]+([.]{1}[0-9]{0,2}){0,1}$/.test(amount.value)==false){
				art.dialog.tips('退款金额输入错误！',2);amount.select();return false;
			}
		}
		if($.trim(tpPerson.value)==''){art.dialog.tips('请选择需要办理退费的乘客！',2);return false;}
		initdata();
		var options = {
			url:'tuifei_tuifei.shtml',
			type:'POST',
			cache:false,
			success:function(result){
				if(result=='T'){
					result = "退费申请成功";
				}
				art.dialog({lock: true,	title : '系统提示',
							content : result + '，2秒后关闭……',
							time : 2,
							close : function() {
									location.reload();
									}
							})
			}
		};
		form.ajaxSubmit(options);
		closeAllDialog();
		art.dialog({
					title:'系统提示',
					id:'system_warn',
					content:'系统正在处理中……',
					lock:true
				});
		return false;
	}
},
{
	name:'取消'
}
);
$('#cause').change(function(){
	if($(this).val()!=''){tpCause.value=$(this).find('option:selected').text();}
	else{tpCause.value='';}
});
$('input[name="ckPerson"]').click(function(){
initdata();
});
initdata=function(){
tpType = $('input[name=tp.type]:checked').val();
tpRepeal.value='';
tpTicketNo.value='';
tpPerson.value='';
	$('input[name="ckPerson"]').each(function(index){
		if($(this).attr('checked')==true){
			var ticket = $(this).parent().parent().find('TD').eq(2).html();
			tpPerson.value+=$(this).parent().parent().find('TD').eq(1).html()+"|";
			if(ticket.indexOf('——')==-1){
				tpTicketNo.value+=ticket+'|';
			}
			if(tpType=='A'){
			tpRepeal.value+='1|'}
			if(tpType=='B'){
			tpRepeal.value+='2|'}
		}else{
			tpRepeal.value+='0|'
		}
	});
	tpRepeal.value=tpRepeal.value.substring(0,tpRepeal.value.length-1);
	tpTicketNo.value=tpTicketNo.value.substring(0,tpTicketNo.value.length-1);
	tpPerson.value=tpPerson.value.substring(0,tpPerson.value.length-1);
}
</script>
